package com.ezia.coreservices.charging.controller;

import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.ezia.coreservices.charging.service.MaPoiService;
import com.ezia.coreservices.charging.utils.ResultMsg;
import com.ezia.coreservices.charging.utils.ResultStatusCode;

import net.sf.json.JSONObject;

@RestController
public class MaPoiController {
	
	private static final Logger logger = LoggerFactory.getLogger(MaPoiController.class);
	
	@Autowired
	private MaPoiService poiService;
	
	@SuppressWarnings("unchecked")
	@RequestMapping(value="v1.0/charging/vehicle/external/search/findbypoiname",method = RequestMethod.POST)
	public Object findByPoiName(@RequestBody String params) {
		logger.info("按照名称查询充电站信息接口");
		logger.info(params);
		Object Result = null;
		ResultMsg resultMsg = null;
		Map<String, Object> paramsDate = (Map<String, Object>)JSONObject.fromObject(params.toString());
		//请求参数判断
		if(null==paramsDate.get("keyword")||null==paramsDate.get("scope")||null==paramsDate.get("coordType")||null==paramsDate.get("userInfo")) 
		{
			resultMsg= new ResultMsg(ResultStatusCode.Parameter_Error.getRespCode(), ResultStatusCode.Parameter_Error.getRespMsg(),
					Result);
			return resultMsg;
		}
		Result = poiService.findByPoiName(paramsDate);
		resultMsg= new ResultMsg(ResultStatusCode.Success.getRespCode(), ResultStatusCode.Success.getRespMsg(),Result);
		return resultMsg; 
	}
	
	@SuppressWarnings("unchecked")
	@RequestMapping(value="v1.0/charging/vehicle/external/search/findbylocation",method = RequestMethod.POST)
	public Object findbylocation(@RequestBody String params) {
		logger.info("获取位置附近的充电场信息（T_API,M_API）");
		logger.info(params);
		Object Result = null;
		ResultMsg resultMsg = null;
		Map<String, Object> paramsDate = (Map<String, Object>)JSONObject.fromObject(params.toString());
		//请求参数判断
		if(null==paramsDate.get("scope")||null==paramsDate.get("coordType")||null==paramsDate.get("latitude")||null==paramsDate.get("longitude")||null==paramsDate.get("userInfo")) 
		{
			resultMsg= new ResultMsg(ResultStatusCode.Parameter_Error.getRespCode(), ResultStatusCode.Parameter_Error.getRespMsg(),
					Result);
			return resultMsg;
		}
		Result = poiService.findbylocation(paramsDate);
		resultMsg= new ResultMsg(ResultStatusCode.Success.getRespCode(), ResultStatusCode.Success.getRespMsg(),Result);
		return resultMsg;
	}
	
	@SuppressWarnings("unchecked")
	@RequestMapping(value ="v1.0/charging/vehicle/external/search/getdynamicinfo",method = RequestMethod.POST)
	public Object getdynamicinfo(@RequestBody String params) {
		logger.info("查询充电站的动态信息接口");
		logger.info(params);
		Map<String, Object> paramsDate = (Map<String, Object>)JSONObject.fromObject(params.toString());
		Object Result = null;
		ResultMsg resultMsg = null;
		if(null==paramsDate.get("CPO_id")||null==paramsDate.get("stationId")||null==paramsDate.get("userInfo")) //
		{
			resultMsg= new ResultMsg(ResultStatusCode.Parameter_Error.getRespCode(), ResultStatusCode.Parameter_Error.getRespMsg(),
					Result);
			return resultMsg;
		}
		Result = poiService.getdynamicinfo(paramsDate);
		resultMsg= new ResultMsg(ResultStatusCode.Success.getRespCode(), ResultStatusCode.Success.getRespMsg(),Result);
		return resultMsg;
	}
		
}
